/**
 * Created by hanj on 2022/3/19 13:52
 */
package com.example.demo;

import com.example.demo.entity.Student;
import com.example.demo.entity.Teacher;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * 线程 2
 *
 */
public class Thread2 implements Runnable {

    //通过上下文实现bean注入

    //线程计数器
    private CountDownLatch latch;

    //参数

    public Thread2() {
    }

    public Thread2(CountDownLatch latch) {
        this.latch = latch;

    }

    @Override
    public void run() {
        try{
            System.out.println(Thread.currentThread().getName() + "future2启动中。。。。。。");
            TimeUnit.MICROSECONDS.sleep(2L);
            List<Teacher> data = getData();
            System.out.println(Thread.currentThread().getName() + "future2打印：" + data);


        } catch (Exception e){
            System.err.println(e.getMessage());
        }finally {
            latch.countDown();
            System.out.println(Thread.currentThread().getName() + "latch数量：" + latch.getCount());
        }
    }

    //模拟导出数据
    private List<Teacher> getData() {
        List<Teacher> result = new ArrayList<>();
        Teacher teacher = new Teacher();
        teacher.setName("张三");
        teacher.setAge(11);
        teacher.setProject("语文");
        result.add(teacher);

        Teacher teacher1 = new Teacher();
        teacher1.setName("李四");
        teacher1.setAge(12);
        teacher1.setProject("数学");
        result.add(teacher1);
        return result;
    }
}
